var entityCollection = require('../../../Base/server/controllers/EntityCollection');

//通过条码流水ID查找品质记录集
exports.findQCRecordByBizRecordID = function(bizRecordId, completeFun){
    var entity = entityCollection.getEntity("QCRecord");
    entity.find({BizRecord: bizRecordId}, null,
        [
            {
                path: 'QCNorm',
                populate: {
                    path: 'ExtendEnum',
                    select: 'Code Name',
                    model: 'ExtendEnum'
                }
            },
            {path: 'QCStandard'}
        ], function(err, records){
        if(err){
            var newErr = new Error();
            newErr.leval = 9;
            newErr.title = '查询品质记录错误';
            newErr.message = '查询失败，请检查查询参数！';
            completeFun(newErr);
        }
        else{
            completeFun(null, records);
        }
    });
};

exports.findQCRecords = function (bizRecordId, completeFun) {
    var qcRecord = entityCollection.getEntity("QCRecord");
    qcRecord.Entity.find({
        BizRecord: bizRecordId
    }, { 
        BadPosition: 1, BadType: 1, Images: 1, Description: 1
    }).exec(function (err, records) {
        if (err) {
            var newErr = new Error();
            newErr.leval = 9;
            newErr.title = '查询品质记录错误';
            newErr.message = '查询失败，请检查查询参数！';
            completeFun(newErr);
            return;
        }
        completeFun(null, records);
    });
};